home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / AmigaSystem / Scalos / GuiGFXLib / src / guigfx_draw.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  49.3 KB  |  2,088 lines

  1. /*********************************************************************
  2. ----------------------------------------------------------------------
  3.  
  4.     guigfx_draw
  5.  
  6. ----------------------------------------------------------------------
  7. *********************************************************************/
  8.  
  9. #include <render/render.h>
  10. #include <render/renderhooks.h>
  11. #include <libraries/cybergraphics.h>
  12. #include <utility/tagitem.h>
  13. #include <graphics/gfx.h>
  14. #include <graphics/view.h>
  15.  
  16. #include <proto/render.h>
  17. #include <proto/graphics.h>
  18. #include <proto/exec.h>
  19. #include <proto/utility.h>
  20. #include <proto/cybergraphics.h>
  21.  
  22. #include <guigfx/guigfx.h>
  23.  
  24. #include "guigfx_global.h"
  25. #include "guigfx_picturemethod.h"
  26. #include "guigfx_bitmap.h"
  27.  
  28.  
  29. #define HOOKDELAY 2
  30.  
  31. /*---------------------------------------------------------------------
  32.  
  33.     Zeichenstrukturen
  34.  
  35. --------------------------------------------------------------------*/
  36.  
  37. struct DrawData
  38. {
  39.     APTR array;
  40.     UWORD totalwidth;
  41.     ULONG pixelformat;
  42.  
  43.     APTR sourcepalette;
  44.     APTR destpalette;
  45.     UBYTE *pentab;
  46.  
  47.     WORD sourcex, sourcey;
  48.     UWORD sourcewidth, sourceheight;
  49.     
  50.     UWORD destx, desty;
  51.     UWORD destwidth, destheight;
  52.  
  53.     DRAWHANDLE *dh;
  54.     UWORD dithermode;        /* hat Vorrang vor dem Dithermode im Drawhandle */
  55.     UWORD ditheramount;
  56.  
  57.     struct Hook *callbackhook;
  58.     PIC *pic;
  59.     
  60.     UWORD colormode;
  61.     
  62.     WORD *coords;
  63.     
  64.     BOOL clearbg;
  65.     
  66.     BOOL autodither;
  67.     
  68. //    ULONG bgcolor;
  69.  
  70.     BOOL    usescalepixelarray;
  71.     
  72.     struct SignalSemaphore *rastlock;
  73.  
  74. };
  75.  
  76. struct drawdata_truecolor
  77. {
  78.     struct RastPort *rp;
  79.     UWORD x, y, width;
  80.     struct Hook *hook;
  81.     PIC *pic;
  82.     ULONG *linebuffer;        // for clearing
  83.     ULONG bgcolor;            // with that color
  84.     struct SignalSemaphore *rastlock;
  85.     WORD hookdelaycount;
  86. };
  87.  
  88. struct drawdata_chunkytruecolor
  89. {
  90.     struct RastPort *rp;
  91.     UWORD x, y, width;
  92.     APTR palette;
  93.     ULONG *rgbbuffer;
  94.     struct Hook *hook;
  95.     PIC *pic;
  96.     UBYTE *linebuffer;        // for clearing
  97.     UBYTE bgpen;            // with that color
  98.     struct SignalSemaphore *rastlock;
  99.     WORD hookdelaycount;
  100. };
  101.  
  102. struct drawdata_chunkyclut
  103. {
  104.     struct RastPort *rp, *temprp;
  105.     UWORD x, y, width;
  106.     struct Hook *hook;
  107.     PIC *pic;
  108.     UBYTE *linebuffer;        // for clearing
  109.     UBYTE bgpen;            // with that color
  110.     struct SignalSemaphore *rastlock;
  111.     WORD hookdelaycount;
  112. };
  113.  
  114. struct drawdata_chunkybitmap
  115. {
  116.     struct BitMap *bm;
  117.     UWORD x, y, width;
  118.     struct Hook *hook;
  119.     PIC *pic;
  120.     UBYTE *linebuffer;        // for clearing
  121.     UBYTE bgpen;            // with that color
  122.     WORD hookdelaycount;
  123. };
  124.  
  125.  
  126.  
  127. /*--------------------------------------------------------------------
  128.  
  129.         continue = calldrawhook(hook, pic, zeile)
  130.  
  131.         führt den User-Callback-Hook mit der Message
  132.         GGFX_MSGTYPE_LINEDRAWN für Zeichenoperationen aus.
  133.  
  134.         Konventionen: die Funktion muß TRUE oder FALSE zurückliefern.
  135.  
  136. --------------------------------------------------------------------*/
  137.  
  138. ULONG __inline calldrawhook (struct Hook *hook, PIC *pic, ULONG zeile)
  139. {
  140.     if (hook)
  141.     {
  142.         return CallHook(hook, (Object *) pic,
  143.             (ULONG) GGFX_MSGTYPE_LINEDRAWN, (ULONG) zeile);
  144.     }
  145.  
  146.     return TRUE;
  147. }
  148.  
  149.  
  150. /*--------------------------------------------------------------------
  151.  
  152.         dithermode = GetDitherMode
  153.         (drawhandle, array, palette, width, height, pixelformat, totalwidth, autodither)
  154.  
  155. --------------------------------------------------------------------*/
  156.  
  157. ULONG GetDitherMode(DRAWHANDLE *dh, APTR array, PALETTE palette,
  158.     UWORD width, UWORD height, ULONG pixelformat, UWORD totalwidth, UWORD defaultmode,
  159.     BOOL autodither)
  160. {
  161.     if (dh)
  162.     {
  163.         if (dh->rasthandle->colormode == COLORMODE_CLUT)
  164.         {
  165.             if (autodither && (defaultmode != DITHERMODE_NONE) && !dh->rasthandle->truecolor)
  166.             {
  167.                 ULONG d = 0;
  168.         
  169.                 switch (pixelformat)
  170.                 {
  171.                     case PIXFMT_CHUNKY_CLUT:
  172.                     
  173.                         #ifdef DEBUG
  174.                         if (!palette)
  175.                         {
  176.                             DB(kprintf("*** Error: No palette specified for ChunkyArrayiversity.\n"));
  177.                         }
  178.                         #endif
  179.                     
  180.                         d = ChunkyArrayDiversity(array, palette,
  181.                                 width, height,
  182.                                 RND_MapEngine, dh->mapengine,
  183.                                 RND_Palette, dh->realpalette,
  184.                                 RND_SourceWidth, totalwidth,
  185.                                 RND_Interleave, DEFAULT_PICTURE_INTERLEAVE, TAG_DONE);
  186.                         break;
  187.         
  188.                     case PIXFMT_0RGB_32:
  189.                         d = RGBArrayDiversity(array,
  190.                                 width, height,
  191.                                 RND_MapEngine, dh->mapengine,
  192.                                 RND_Palette, dh->realpalette,
  193.                                 RND_SourceWidth, totalwidth,
  194.                                 RND_Interleave, DEFAULT_PICTURE_INTERLEAVE, TAG_DONE);
  195.                         break;
  196.     
  197.                     default:
  198.                         DB(kprintf("***error: undefined pixelformat in getdithermode\n"));
  199.                         break;
  200.                 }
  201.     
  202.                 DB(kprintf("diversity: %ld  ", d));
  203.                 DB(kprintf("threshold: %ld\n", dh->ditherthreshold));
  204.         
  205.                 if (d > dh->ditherthreshold)
  206.                 {
  207.                     return defaultmode;
  208.                 }
  209.                 else
  210.                 {
  211.                     return DITHERMODE_NONE;
  212.                 }
  213.             }
  214.         }
  215.     }
  216.  
  217.     return defaultmode;
  218. }
  219.  
  220.  
  221. /*---------------------------------------------------------------------
  222.  
  223.     drawchunkytruecolor
  224.  
  225.     callback zum Zeichnen von Chunky-Daten auf Truecolor
  226.  
  227. --------------------------------------------------------------------*/
  228.  
  229. #ifdef __MORPHOS__
  230. FUNC_HOOK(ULONG, drawchunkytruecolor, struct Hook *, hook, APTR, buffer, struct RND_LineMessage *, msg)
  231. #else
  232. ULONG ASM SAVE_DS drawchunkytruecolor(    register __a0 struct Hook *hook,
  233.                                         register __a2 APTR buffer,
  234.                                         register __a1 struct RND_LineMessage *msg )
  235. #endif
  236. {
  237.     ULONG result = TRUE;
  238.  
  239.     struct drawdata_chunkytruecolor *data = hook->h_Data;
  240.  
  241.     switch (msg->RND_LMsg_type)
  242.     {
  243.         case LMSGTYPE_LINE_FETCH:
  244.         {
  245.             if (data->linebuffer)
  246.             {
  247.                 TurboFillMem(data->linebuffer, data->width, data->bgpen);
  248.             }
  249.             break;
  250.         }
  251.  
  252.         case LMSGTYPE_LINE_RENDERED:
  253.         {
  254.             Chunky2RGB((UBYTE *)buffer, data->width, 1, data->rgbbuffer, data->palette, NULL);
  255.     
  256.             if (data->rastlock) ObtainSemaphore(data->rastlock);
  257.  
  258.             WritePixelArray(data->rgbbuffer, 0, 0, data->width, data->rp,
  259.                 data->x, data->y, data->width, 1, RECTFMT_ARGB);
  260.  
  261.             if (data->rastlock) ReleaseSemaphore(data->rastlock);
  262.     
  263.             if (--data->hookdelaycount < 0)
  264.             {
  265.                 result = calldrawhook(data->hook, data->pic, data->y);
  266.                 data->hookdelaycount = HOOKDELAY;
  267.             }
  268.             else
  269.             {
  270.                 result = TRUE;
  271.             }
  272.     
  273.             data->y++;
  274.  
  275.             break;
  276.         }
  277.     }
  278.  
  279.     return result;
  280. }
  281.  
  282.  
  283. /*---------------------------------------------------------------------
  284.  
  285.     drawtruecolor
  286.  
  287.     callback zum Zeichnen von Truecolor auf Truecolor
  288.  
  289. --------------------------------------------------------------------*/
  290.  
  291. #ifdef __MORPHOS__
  292. FUNC_HOOK(ULONG, drawtruecolor, struct Hook *, hook, APTR, buffer, struct RND_LineMessage *, msg)
  293. #else
  294. ULONG ASM SAVE_DS drawtruecolor(    register __a0 struct Hook *hook,
  295.                                     register __a2 APTR buffer,
  296.                                     register __a1 struct RND_LineMessage *msg )
  297. #endif
  298. {
  299.     ULONG result = TRUE;
  300.     struct drawdata_truecolor *data = hook->h_Data;
  301.  
  302.     switch (msg->RND_LMsg_type)
  303.     {
  304.         case LMSGTYPE_LINE_FETCH:
  305.         {
  306.             ULONG *p;
  307.             
  308.             if (p = data->linebuffer)
  309.             {
  310.                 int i;
  311.                 for (i = 0; i < data->width; ++i)
  312.                 {
  313.                     *p++ = data->bgcolor;
  314.                 }
  315.             }
  316.             break;
  317.         }
  318.  
  319.         case LMSGTYPE_LINE_RENDERED:
  320.         {
  321.             if (data->rastlock) ObtainSemaphore(data->rastlock);
  322.  
  323.             WritePixelArray(buffer, 0, 0, data->width, data->rp, data->x, data->y,
  324.                 data->width, 1, RECTFMT_ARGB);
  325.  
  326.             if (data->rastlock) ReleaseSemaphore(data->rastlock);
  327.  
  328.             if (--data->hookdelaycount < 0)
  329.             {
  330.                 result = calldrawhook(data->hook, data->pic, data->y);
  331.                 data->hookdelaycount = HOOKDELAY;
  332.             }
  333.             else
  334.             {
  335.                 result = TRUE;
  336.             }
  337.  
  338.             data->y++;
  339.         
  340.             break;
  341.         }
  342.     }
  343.  
  344.     return result;
  345. }
  346.  
  347.  
  348. /*---------------------------------------------------------------------
  349.  
  350.     drawchunkyclut
  351.  
  352.     callback zum Zeichnen von Chunky-Daten auf CLUT
  353.  
  354. --------------------------------------------------------------------*/
  355.  
  356. #ifdef __MORPHOS__
  357. FUNC_HOOK(ULONG, drawchunkyclut, struct Hook *, hook, APTR, buffer, struct RND_LineMessage *, msg)
  358. #else
  359. ULONG ASM SAVE_DS drawchunkyclut(    register __a0 struct Hook *hook,
  360.                                     register __a2 APTR buffer,
  361.                                     register __a1 struct RND_LineMessage *msg )
  362. #endif
  363. {
  364.     struct drawdata_chunkyclut *data = hook->h_Data;
  365.  
  366.     ULONG result = TRUE;
  367.  
  368.     switch (msg->RND_LMsg_type)
  369.     {
  370.         case LMSGTYPE_LINE_FETCH:
  371.         {
  372.             if (data->linebuffer)
  373.             {
  374.                 TurboFillMem(data->linebuffer, data->width, data->bgpen);
  375.             }
  376.             break;
  377.         }
  378.  
  379.         case LMSGTYPE_LINE_RENDERED:
  380.         {
  381.             if (data->rastlock) ObtainSemaphore(data->rastlock);
  382.  
  383.             WritePixelLine8(data->rp, data->x, data->y, data->width,
  384.                     buffer, data->temprp);
  385.  
  386.             if (data->rastlock) ReleaseSemaphore(data->rastlock);
  387.  
  388.             if (--data->hookdelaycount < 0)
  389.             {
  390.                 result = calldrawhook(data->hook, data->pic, data->y);
  391.                 data->hookdelaycount = HOOKDELAY;
  392.             }
  393.             else
  394.             {
  395.                 result = TRUE;
  396.             }
  397.     
  398.             data->y++;
  399.  
  400.             break;
  401.         }
  402.     }
  403.  
  404.     return result;
  405. }
  406.  
  407.  
  408. /*---------------------------------------------------------------------
  409.  
  410.     drawchunkybitmap
  411.  
  412.     callback zum Zeichnen von Chunky-Daten
  413.     in eine BMF_STANDARD BitMap
  414.  
  415. --------------------------------------------------------------------*/
  416.  
  417. #ifdef __MORPHOS__
  418. FUNC_HOOK(ULONG, drawchunkybitmap, struct Hook *, hook, APTR, buffer, struct RND_LineMessage *, msg)
  419. #else
  420. ULONG ASM SAVE_DS drawchunkybitmap    (    register __a0 struct Hook *hook,
  421.                                         register __a2 APTR buffer,
  422.                                         register __a1 struct RND_LineMessage *msg )
  423. #endif
  424. {
  425.     ULONG result = TRUE;
  426.     struct drawdata_chunkybitmap *data = hook->h_Data;
  427.  
  428.     switch (msg->RND_LMsg_type)
  429.     {
  430.         case LMSGTYPE_LINE_FETCH:
  431.         {
  432.             if (data->linebuffer)
  433.             {
  434.                 TurboFillMem(data->linebuffer, data->width, data->bgpen);
  435.             }
  436.             break;
  437.         }
  438.  
  439.         case LMSGTYPE_LINE_RENDERED:
  440.         {
  441.             Chunky2BitMapA(buffer, 0, 0, data->width, 1, data->bm, data->x, data->y, NULL);
  442.  
  443.             if (--data->hookdelaycount < 0)
  444.             {
  445.                 result = calldrawhook(data->hook, data->pic, data->y);
  446.                 data->hookdelaycount = HOOKDELAY;
  447.             }
  448.             else
  449.             {
  450.                 result = TRUE;
  451.             }
  452.     
  453.             data->y++;
  454.  
  455.             break;
  456.         }
  457.     }
  458.  
  459.     return result;
  460. }
  461.  
  462.  
  463.  
  464.  
  465. /*---------------------------------------------------------------------
  466.  
  467.     CreateDrawData
  468.  
  469.     erzeugt eine Drawdata-Struktur
  470.  
  471. --------------------------------------------------------------------*/
  472.  
  473. struct DrawData *CreateDrawData(DRAWHANDLE *dh, PIC *pic)
  474. {
  475.     struct DrawData *data;
  476.     
  477.     if (data = AllocRenderVecClear(MemHandler, sizeof(struct DrawData)))
  478.     {
  479.         data->ditheramount = DEFAULT_DITHERAMOUNT;
  480.  
  481.         if (pic)
  482.         {
  483.             data->array = pic->array;
  484.             data->totalwidth = pic->width;
  485.             data->pic = pic;
  486.             data->sourcepalette = pic->palette;
  487.             data->sourcewidth = pic->width;
  488.             data->sourceheight = pic->height;
  489.             data->destwidth = pic->width;
  490.             data->destheight = pic->height;
  491.             data->pixelformat = pic->pixelformat;
  492.             data->colormode = COLORMODE_CLUT;
  493.         }
  494.         
  495.         if (dh)
  496.         {
  497.             data->dh = dh;
  498.             data->dithermode = dh->dithermode;
  499.             data->ditheramount = dh->ditheramount;
  500.             data->destpalette = dh->realpalette;
  501.             data->pentab = dh->mainpentab;
  502.             data->colormode = dh->rasthandle->colormode;
  503.         }
  504.     }
  505.     
  506.     return data;
  507. }
  508.  
  509.  
  510.  
  511. /*---------------------------------------------------------------------
  512.  
  513.     DrawRastHandle
  514.  
  515.     allgemeine Zeichenfunktion zum Zeichnen in ein RastHandle
  516.  
  517. --------------------------------------------------------------------*/
  518.  
  519. BOOL DrawRastHandle(RASTHANDLE *rh, struct DrawData *data)
  520. {
  521.     UBYTE *p;
  522.     APTR scaleengine = NULL;
  523.     BOOL success = TRUE;
  524.     BOOL directdraw;
  525.     BOOL scaling = FALSE;
  526.     PIC *pic = data->pic;
  527.  
  528.  
  529.     if (!calldrawhook(data->callbackhook, pic, 0))
  530.     {
  531.         return FALSE;
  532.     }
  533.  
  534.  
  535.     if (data->dh && pic)
  536.     {
  537.         directdraw = !!(pic->directdraw == data->dh);
  538.     }
  539.     else
  540.     {
  541.         directdraw = FALSE;
  542.     }
  543.  
  544.  
  545.     p = ((UBYTE *) data->array) +
  546.         PIXELSIZE(data->pixelformat) * (data->sourcex + data->sourcey * data->totalwidth);
  547.  
  548.  
  549.     if (data->coords ||
  550.         (data->sourcewidth != data->destwidth) || (data->sourceheight != data->destheight))
  551.     {
  552.         ULONG pixelformat = data->pixelformat;
  553.  
  554.         BOOL newengine = TRUE;
  555.  
  556.  
  557.         if (!data->coords)
  558.         {
  559.             DB(kprintf("§§§no coordinates\n"));
  560.  
  561.             if ((data->sourcewidth == data->destwidth) && (data->sourceheight == data->destheight))
  562.             {
  563.                 DB(kprintf("§§§no scaling required\n"));
  564.  
  565.                 DeleteScaleEngine(pic->scaleengine);
  566.                 pic->scaleengine = NULL;
  567.                 newengine = FALSE;
  568.             }
  569.  
  570.             if (newengine)
  571.             {
  572.                 if (rh->truecolor && (pixelformat == PIXFMT_0RGB_32))
  573.                 {
  574.                     if (data->usescalepixelarray)
  575.                     {
  576.                         DB(kprintf("§§§no scaling required with cgfx v41\n"));
  577.  
  578.                         DeleteScaleEngine(pic->scaleengine);
  579.                         pic->scaleengine = NULL;
  580.                         newengine = FALSE;
  581.                     }
  582.                 }
  583.             }
  584.             
  585.             if (newengine)
  586.             {
  587.                 if (pic->scaleengine)
  588.                 {
  589.                     if (pic->scalepixelformat == pixelformat &&
  590.                         pic->scalesourcewidth == data->sourcewidth &&
  591.                         pic->scalesourceheight == data->sourceheight &&
  592.                         pic->scaledestwidth == data->destwidth &&
  593.                         pic->scaledestheight == data->destheight)
  594.                     {
  595.                         DB(kprintf("§§§ using old scaling engine...\n"));
  596.                         newengine = FALSE;
  597.                     }
  598.                 }
  599.             }
  600.         }
  601.  
  602.         if (newengine)
  603.         {
  604.             DeleteScaleEngine(pic->scaleengine);
  605.  
  606.             DB(kprintf("§§§creating scaling engine...\n"));
  607.             
  608.             if (pic->scaleengine = CreateScaleEngine(data->sourcewidth, data->sourceheight,
  609.                 data->destwidth, data->destheight, RND_PixelFormat, pixelformat,
  610.                 RND_DestCoordinates, data->coords,
  611.                 RND_RMHandler, MemHandler, TAG_DONE))
  612.             {
  613.                 pic->scalepixelformat = pixelformat;
  614.                 pic->scalesourcewidth = data->sourcewidth;
  615.                 pic->scalesourceheight = data->sourceheight;
  616.                 pic->scaledestwidth = data->destwidth;
  617.                 pic->scaledestheight = data->destheight;
  618.             }
  619.             else
  620.             {
  621.                 success = FALSE;
  622.             }
  623.         }
  624.  
  625.         scaling = TRUE;
  626.         scaleengine = pic->scaleengine;
  627.     }
  628.  
  629.  
  630.     if (success)
  631.     {
  632.         UBYTE *linebuffer;
  633.         success = FALSE;
  634.  
  635.         if (rh->truecolor)
  636.         {
  637.             /*
  638.              *    auf truecolor zeichnen
  639.              */
  640.  
  641.             switch (data->pixelformat)
  642.             {
  643.                 case PIXFMT_CHUNKY_CLUT:
  644.                 {
  645.                     if (scaleengine)
  646.                     {
  647.                         if (linebuffer = AllocRenderVec(MemHandler, data->destwidth*5))
  648.                         {
  649.                             struct Hook drawhook;
  650.                             struct drawdata_chunkytruecolor hookdata;
  651.     
  652.                             hookdata.rp = rh->rp;
  653.                             hookdata.x = data->destx;
  654.                             hookdata.y = data->desty;
  655.                             hookdata.width = data->destwidth;
  656.                             hookdata.palette = data->sourcepalette;
  657.                             hookdata.rgbbuffer = (ULONG *) linebuffer;
  658.                             hookdata.hook = data->callbackhook;
  659.                             hookdata.pic = pic;
  660.                             hookdata.rastlock = data->rastlock;
  661.                             hookdata.hookdelaycount = 0;
  662.                             if (data->clearbg)
  663.                             {
  664.                                 hookdata.bgpen = BestPen(pic->palette, data->dh->bgcolor);
  665.                                 hookdata.linebuffer = linebuffer + data->destwidth * 4;
  666.                             }
  667.                             else
  668.                             {
  669.                                 hookdata.linebuffer = NULL;
  670.                             }                        
  671.                             drawhook.h_Data = &hookdata;
  672. #ifdef __MORPHOS__
  673.                             drawhook.h_Entry = (HOOKFUNC) &drawchunkytruecolor;
  674. #else
  675.                             drawhook.h_Entry = (HOOKFUNC) drawchunkytruecolor;
  676. #endif
  677.  
  678.                             DB(kprintf("drawing/scaling chunky to truecolor\n"));
  679.             
  680.                             success = !!(Scale(scaleengine, (APTR) p, linebuffer + data->destwidth*4,
  681.                                 RND_SourceWidth, data->totalwidth, RND_DestWidth, 0,
  682.                                 RND_LineHook, &drawhook, TAG_DONE) == CONV_SUCCESS);
  683.  
  684.                             FreeRenderVec(linebuffer);
  685.                         }
  686.                     }
  687.                     else
  688.                     {
  689.                         if (linebuffer = AllocRenderVec(MemHandler, data->destwidth*4))
  690.                         {
  691.                             struct Hook drawhook;
  692.                             struct drawdata_truecolor hookdata;
  693.     
  694.                             hookdata.rp = rh->rp;
  695.                             hookdata.x = data->destx;
  696.                             hookdata.y = data->desty;
  697.                             hookdata.width = data->destwidth;
  698.                             hookdata.hook = data->callbackhook;
  699.                             hookdata.pic = pic;
  700.                             hookdata.rastlock = data->rastlock;
  701.                             hookdata.hookdelaycount = 0;
  702.                             if (data->clearbg)
  703.                             {
  704.                                 hookdata.bgcolor = data->dh->bgcolor;
  705.                                 hookdata.linebuffer = (ULONG *) linebuffer;
  706.                             }
  707.                             else
  708.                             {
  709.                                 hookdata.linebuffer = NULL;
  710.                             }                        
  711.                             drawhook.h_Data = &hookdata;
  712. #ifdef __MORPHOS__
  713.                             drawhook.h_Entry = (HOOKFUNC) &drawtruecolor;
  714. #else
  715.                             drawhook.h_Entry = (HOOKFUNC) drawtruecolor;
  716. #endif
  717.  
  718.                             DB(kprintf("drawing chunky to truecolor\n"));
  719.  
  720.                             success = !!(Chunky2RGB((APTR) p, data->destwidth, data->destheight,
  721.                                 (ULONG *) linebuffer, data->sourcepalette, RND_LineHook, &drawhook,
  722.                                 RND_SourceWidth, data->totalwidth,
  723.                                 RND_DestWidth, 0, TAG_DONE) == CONV_SUCCESS);
  724.  
  725.                             FreeRenderVec(linebuffer);
  726.                         }
  727.                     }
  728.                     break;
  729.                 }
  730.  
  731.                 case PIXFMT_0RGB_32:
  732.                 {
  733.                     if (scaling)
  734.                     {
  735.                         DB(kprintf("drawing/scaling truecolor to truecolor\n"));
  736.  
  737.                 //        if (cgfx41 && env_usescalepixelarray)
  738.                         if (!scaleengine && cgfx41)
  739.                         {
  740.                     //        success = calldrawhook(NULL, pic, 0);
  741.                     //        if (success)
  742.                     //        {
  743.                                 ScalePixelArray((APTR)p, data->sourcewidth, data->sourceheight, 
  744.                                     data->totalwidth*4, rh->rp, data->destx, data->desty, data->destwidth,
  745.                                     data->destheight, RECTFMT_ARGB);
  746.                     //        }
  747.                             success = TRUE;
  748.                         }
  749.                         else
  750.                         {
  751.                             if (linebuffer = AllocRenderVec(MemHandler, data->destwidth*4))
  752.                             {
  753.                                 struct Hook drawhook;
  754.                                 struct drawdata_truecolor hookdata;
  755.     
  756.                                 hookdata.rp = rh->rp;
  757.                                 hookdata.x = data->destx;
  758.                                 hookdata.y = data->desty;
  759.                                 hookdata.width = data->destwidth;
  760.                                 hookdata.hook = data->callbackhook;
  761.                                 hookdata.pic = pic;
  762.                                 hookdata.rastlock = data->rastlock;
  763.                                 hookdata.hookdelaycount = 0;
  764.                                 if (data->clearbg)
  765.                                 {
  766.                                     hookdata.bgcolor = data->dh->bgcolor;
  767.                                     hookdata.linebuffer = (ULONG *) linebuffer;
  768.                                 }
  769.                                 else
  770.                                 {
  771.                                     hookdata.linebuffer = NULL;
  772.                                 }
  773.                                 drawhook.h_Data = &hookdata;
  774. #ifdef __MORPHOS__
  775.                                 drawhook.h_Entry = (HOOKFUNC) &drawtruecolor;
  776. #else
  777.                                 drawhook.h_Entry = (HOOKFUNC) drawtruecolor;
  778. #endif
  779.  
  780.                                 success = !!(Scale(scaleengine, (APTR) p, linebuffer,
  781.                                     RND_SourceWidth, data->totalwidth, RND_DestWidth, 0,
  782.                                     RND_LineHook, &drawhook, TAG_DONE) == CONV_SUCCESS);
  783.                         
  784.                                 FreeRenderVec(linebuffer);
  785.                             }
  786.                         }
  787.                     }
  788.                     else
  789.                     {
  790.                         DB(kprintf("drawing truecolor to truecolor\n"));
  791.  
  792.                         WritePixelArray((APTR) data->array, data->sourcex, data->sourcey,
  793.                             data->totalwidth*4, rh->rp, data->destx, data->desty,
  794.                             data->destwidth, data->destheight, RECTFMT_ARGB);
  795.                         success = TRUE;
  796.                     }
  797.                     break;
  798.                 }
  799.  
  800.                 #ifdef DEBUG                
  801.                 default:
  802.                 {
  803.                     DB(kprintf("*** Illegal condition: undefined pixelformat.\n"));
  804.                     break;
  805.                 }
  806.                 #endif
  807.             }
  808.         }
  809.         else
  810.         {
  811.             /*
  812.              *    auf clut zeichnen
  813.              */
  814.  
  815.             switch (data->pixelformat)
  816.             {
  817.                 case PIXFMT_CHUNKY_CLUT:
  818.                 {
  819.                     if (directdraw)
  820.                     {
  821.                         if (scaleengine)
  822.                         {
  823.                             /*
  824.                              *    zuerst versuchen, den ganzen Block zu skalieren und zu zeichnen
  825.                              */
  826.                             
  827.                             if (rh->drawmode == DRAWMODE_CYBERGFX)
  828.                             { 
  829.                                 UBYTE *buffer;
  830.                                 if (buffer = AllocRenderVec(MemHandler, data->destwidth * data->destheight))
  831.                                 {
  832.                                     if (data->clearbg)
  833.                                     {
  834.                                         TurboFillMem(buffer, data->destwidth * data->destheight, data->dh->bgpen);
  835.                                     }
  836.                                 
  837.                                     DB(kprintf("scaling/drawing chunky to chunky block-wise in directdraw mode\n"));
  838.  
  839.                                     if (Scale(scaleengine, (APTR) p, buffer,
  840.                                         RND_SourceWidth, data->totalwidth, TAG_DONE) == CONV_SUCCESS)
  841.                                     {
  842.                                         WritePixelArray((APTR)buffer, 0, 0, data->destwidth, rh->rp,
  843.                                             data->destx, data->desty, data->destwidth, data->destheight, RECTFMT_LUT8);
  844.  
  845.                                         success = TRUE;
  846.                                     }
  847.                                     FreeRenderVec(buffer);
  848.                                 }
  849.                             }
  850.                             
  851.                             if (!success)
  852.                             {
  853.                                 if (linebuffer = AllocRenderVec(MemHandler, (data->destwidth + 15) & ~15))
  854.                                 {
  855.                                     switch (rh->drawmode)
  856.                                     {
  857.                                         case DRAWMODE_BITMAP:
  858.                                         {
  859.                                             struct BitMap *bm;
  860.         
  861.                                             DB(kprintf("blitting chunky to chunky in directdraw mode\n"));
  862.                                             
  863.                                             if (bm = AllocBitMap(data->destwidth, data->destheight, rh->rp->BitMap->Depth, BMF_STANDARD+BMF_INTERLEAVED, NULL/*rh->rp->BitMap*/))
  864.                                             {
  865.                                                 struct Hook drawhook;
  866.                                                 struct drawdata_chunkybitmap hookdata;
  867.                         
  868.                                                 hookdata.bm = bm;
  869.                                                 hookdata.x = 0;
  870.                                                 hookdata.y = 0;
  871.                                                 hookdata.width = data->destwidth;
  872.                                                 hookdata.hook = NULL;    /*data->callbackhook;*/
  873.                                                 hookdata.pic = NULL;     /*data->pic;*/
  874.                                                 hookdata.hookdelaycount = 0;
  875.                                                 if (data->clearbg)
  876.                                                 {
  877.                                                     hookdata.bgpen = data->dh->bgpen;
  878.                                                     hookdata.linebuffer = (UBYTE *) linebuffer;
  879.                                                 }
  880.                                                 else
  881.                                                 {
  882.                                                     hookdata.linebuffer = NULL;
  883.                                                 }                        
  884.                                                 drawhook.h_Data = &hookdata;
  885. #ifdef __MORPHOS__
  886.                                                 drawhook.h_Entry = (HOOKFUNC) &drawchunkybitmap;
  887. #else
  888.                                                 drawhook.h_Entry = (HOOKFUNC) drawchunkybitmap;
  889. #endif
  890.  
  891.                                                 if (Scale(scaleengine, (APTR) p, linebuffer,
  892.                                                     RND_SourceWidth, data->totalwidth, RND_DestWidth, 0,
  893.                                                     RND_LineHook, &drawhook, TAG_DONE) == CONV_SUCCESS)
  894.                                                 {
  895.                                                     if (data->rastlock) ObtainSemaphore(data->rastlock);
  896.  
  897.                                                     BltBitMapRastPort(bm, 0, 0, rh->rp, data->destx, data->desty,
  898.                                                         data->destwidth, data->destheight, 0xc0);
  899.                                                     
  900.                                                     if (data->rastlock) ReleaseSemaphore(data->rastlock);
  901.  
  902.                                                     success = TRUE;
  903.                                                 }
  904.                                         
  905.                                                 FreeBitMap(bm);
  906.                                             }
  907.                                             break;
  908.                                         }
  909.                                         default:
  910.                                         {
  911.                                             struct Hook drawhook;
  912.                                             struct drawdata_chunkyclut hookdata;
  913.                         
  914.                                             hookdata.rp = rh->rp;
  915.                                             hookdata.temprp = rh->temprp;
  916.                                             hookdata.x = data->destx;
  917.                                             hookdata.y = data->desty;
  918.                                             hookdata.width = data->destwidth;
  919.                                             hookdata.hook = NULL;    /*data->callbackhook;*/
  920.                                             hookdata.pic = NULL;    /*data->pic;*/
  921.                                             hookdata.rastlock = data->rastlock;
  922.                                             hookdata.hookdelaycount = 0;
  923.                                             if (data->clearbg)
  924.                                             {
  925.                                                 hookdata.bgpen = data->dh->bgpen;
  926.                                                 hookdata.linebuffer = (UBYTE *) linebuffer;
  927.                                             }
  928.                                             else
  929.                                             {
  930.                                                 hookdata.linebuffer = NULL;
  931.                                             }                        
  932.                                             drawhook.h_Data = &hookdata;
  933. #ifdef __MORPHOS__
  934.                                             drawhook.h_Entry = (HOOKFUNC) &drawchunkyclut;
  935. #else
  936.                                             drawhook.h_Entry = (HOOKFUNC) drawchunkyclut;
  937. #endif
  938.  
  939.                                             DB(kprintf("drawing/scaling chunky to chunky in directdraw mode\n"));
  940.                             
  941.                                             success = !!(Scale(scaleengine, (APTR) p, linebuffer,
  942.                                                 RND_SourceWidth, data->totalwidth, RND_DestWidth, 0,
  943.                                                 RND_LineHook, &drawhook, TAG_DONE) == CONV_SUCCESS);
  944.                                                 
  945.                                             break;
  946.                                         }
  947.                                     }
  948.                                     FreeRenderVec(linebuffer);
  949.                                 }
  950.                             }
  951.                         }
  952.                         else
  953.                         {
  954.                             if (rh->drawmode == DRAWMODE_BITMAP)
  955.                             {
  956.                                 struct BitMap *bm;
  957.         
  958.                                 DB(kprintf("blitting chunky to chunky in directdraw mode\n"));
  959.                                 
  960.                                 if (bm = AllocBitMap(data->destwidth, data->destheight, rh->rp->BitMap->Depth, BMF_STANDARD+BMF_INTERLEAVED, NULL/*rh->rp->BitMap*/))
  961.                                 {
  962.                                     Chunky2BitMap((UBYTE *) p, 0, 0, data->destwidth,
  963.                                         data->destheight, bm, 0, 0, RND_SourceWidth, data->totalwidth);
  964.  
  965.                                     if (data->rastlock) ObtainSemaphore(data->rastlock);
  966.  
  967.                                     BltBitMapRastPort(bm, 0, 0, rh->rp, data->destx, data->desty,
  968.                                         data->destwidth, data->destheight, 0xc0);
  969.  
  970.                                     if (data->rastlock) ReleaseSemaphore(data->rastlock);
  971.  
  972.                                     success = TRUE;
  973.                             
  974.                                     FreeBitMap(bm);
  975.                                 }
  976.                             }
  977.                             else
  978.                             {
  979.                                 DB(kprintf("drawing chunky to chunky in directdraw mode\n"));
  980.     
  981.                                 if (rh->drawmode == DRAWMODE_CYBERGFX)
  982.                                 {
  983.                                     if (data->rastlock) ObtainSemaphore(data->rastlock);
  984.  
  985.                                     WritePixelArray((APTR) p, 0, 0, data->totalwidth, rh->rp,
  986.                                         data->destx, data->desty, data->destwidth, data->destheight, RECTFMT_LUT8);
  987.  
  988.                                     if (data->rastlock) ReleaseSemaphore(data->rastlock);
  989.                                 }
  990.                                 else
  991.                                 {
  992.                                     if (gfx40)
  993.                                     {
  994.                                         if (data->rastlock) ObtainSemaphore(data->rastlock);
  995.  
  996.                                         WriteChunkyPixels(rh->rp, data->destx, data->desty,
  997.                                             data->destx+data->destwidth-1, data->desty+data->destheight-1,
  998.                                             (APTR) p, data->totalwidth);
  999.  
  1000.                                         if (data->rastlock) ReleaseSemaphore(data->rastlock);
  1001.                                     }
  1002.                                     else
  1003.                                     {
  1004.                                         int i;
  1005.  
  1006.                                         if (data->rastlock) ObtainSemaphore(data->rastlock);
  1007.  
  1008.                                         for (i = data->desty; i < data->desty + data->destheight; ++i)
  1009.                                         {
  1010.                                             WritePixelLine8(rh->rp, data->destx, i,
  1011.                                                 data->destwidth, (APTR) p, rh->temprp);
  1012.                                             p += data->totalwidth;
  1013.                                         }
  1014.  
  1015.                                         if (data->rastlock) ReleaseSemaphore(data->rastlock);
  1016.                                     }
  1017.                                 
  1018.                                 }
  1019.                                 success = TRUE;
  1020.                             }
  1021.                         }
  1022.                     }
  1023.                     else
  1024.                     {
  1025.                         if (linebuffer = AllocRenderVec(MemHandler, (data->destwidth + 15) & ~15))
  1026.                         {
  1027.                             struct Hook drawhook;
  1028.                             struct drawdata_chunkyclut hookdata;
  1029.             
  1030.                             hookdata.rp = rh->rp;
  1031.                             hookdata.temprp = rh->temprp;
  1032.                             hookdata.x = data->destx;
  1033.                             hookdata.y = data->desty;
  1034.                             hookdata.width = data->destwidth;
  1035.                             hookdata.hook = data->callbackhook;
  1036.                             hookdata.pic = pic;
  1037.                             hookdata.rastlock = data->rastlock;
  1038.                             hookdata.hookdelaycount = 0;
  1039.  
  1040.                 /*            if (data->clearbg)
  1041.                             {
  1042.                                 hookdata.bgpen = data->dh->mainpentab[BestPen(data->dh->mainpalette, data->bgcolor)];
  1043.                                 hookdata.linebuffer = (UBYTE *) linebuffer;
  1044.                             }
  1045.                             else
  1046.                             {
  1047.                 */                hookdata.linebuffer = NULL;
  1048.                 //            }                        
  1049.  
  1050.                             drawhook.h_Data = &hookdata;
  1051. #ifdef __MORPHOS__
  1052.                             drawhook.h_Entry = (HOOKFUNC) &drawchunkyclut;
  1053. #else
  1054.                             drawhook.h_Entry = (HOOKFUNC) drawchunkyclut;
  1055. #endif
  1056.  
  1057.                             DB(kprintf("converting/drawing/scaling chunky to chunky\n"));
  1058.                     
  1059.                             success = !!(ConvertChunky((APTR) p, data->sourcepalette,
  1060.                                 data->destwidth, data->destheight, linebuffer, data->destpalette,
  1061.                                 RND_BGPen, BestPen(data->sourcepalette, data->dh->bgcolor),
  1062.                                 RND_PenTable, data->pentab,
  1063.                                 RND_SourceWidth, data->totalwidth, RND_DestWidth, 0,
  1064.                                 RND_ScaleEngine, scaleengine,
  1065.                                 RND_MapEngine, data->dh->mapengine,
  1066.                                 RND_DitherMode,
  1067.                                     GetDitherMode(data->dh, (APTR) p, data->sourcepalette,
  1068.                                         data->sourcewidth, data->sourceheight,
  1069.                                         data->pixelformat, data->totalwidth, data->dithermode, data->autodither),
  1070.                                 RND_LineHook, &drawhook, TAG_DONE) == CONV_SUCCESS);
  1071.                                     
  1072.                             FreeRenderVec(linebuffer);
  1073.                         }
  1074.                     }
  1075.                     break;
  1076.                 }
  1077.  
  1078.                 case PIXFMT_0RGB_32:
  1079.                 {
  1080.                     if (linebuffer = AllocRenderVec(MemHandler, (data->destwidth + 15) & ~15))
  1081.                     {
  1082.                         struct Hook drawhook;
  1083.                         struct drawdata_chunkyclut hookdata;
  1084.  
  1085.                         hookdata.rp = rh->rp;
  1086.                         hookdata.temprp = rh->temprp;
  1087.                         hookdata.x = data->destx;
  1088.                         hookdata.y = data->desty;
  1089.                         hookdata.width = data->destwidth;
  1090.                         hookdata.hook = data->callbackhook;
  1091.                         hookdata.pic = pic;
  1092.                         hookdata.rastlock = data->rastlock;
  1093.                         hookdata.hookdelaycount = 0;
  1094.  
  1095.             /*            if (data->clearbg)
  1096.                         {
  1097.                             hookdata.bgpen = data->dh->mainpentab[BestPen(data->dh->mainpalette, data->bgcolor)];
  1098.                             hookdata.linebuffer = (UBYTE *) linebuffer;
  1099.                         }
  1100.                         else
  1101.                         {
  1102.             */                hookdata.linebuffer = NULL;
  1103.             //            }                        
  1104.                         drawhook.h_Data = &hookdata;
  1105. #ifdef __MORPHOS__
  1106.                         drawhook.h_Entry = (HOOKFUNC) &drawchunkyclut;
  1107. #else
  1108.                         drawhook.h_Entry = (HOOKFUNC) drawchunkyclut;
  1109. #endif
  1110.  
  1111.                         DB(kprintf("converting/drawing/scaling truecolor to chunky\n"));
  1112.  
  1113.                         success = !!(Render((APTR) p, data->destwidth, data->destheight,
  1114.                                 linebuffer, data->destpalette,
  1115.                                 RND_BGColor, data->dh->bgcolor,
  1116.                                 RND_PenTable, data->pentab,
  1117.                                 RND_SourceWidth, data->totalwidth,
  1118.                                 RND_DestWidth, 0,
  1119.                                 RND_ScaleEngine, scaleengine,
  1120.                                 RND_MapEngine, data->dh->mapengine,
  1121.                                 RND_ColorMode, data->colormode,
  1122.                                 RND_DitherMode,
  1123.                                     GetDitherMode(data->dh, (APTR) p, NULL,
  1124.                                         data->sourcewidth, data->sourceheight,
  1125.                                         data->pixelformat, data->totalwidth,
  1126.                                         data->dithermode, data->autodither),
  1127.                                 RND_LineHook, &drawhook, 
  1128.                                 TAG_DONE) == REND_SUCCESS);
  1129.                             
  1130.                         FreeRenderVec(linebuffer);
  1131.                     }
  1132.                     break;
  1133.                 }
  1134.                 
  1135.                 #ifdef DEBUG                
  1136.                 default:
  1137.                 {
  1138.                     DB(kprintf("*** Illegal condition: undefined pixelformat.\n"));
  1139.                     break;
  1140.                 }
  1141.                 #endif
  1142.                 
  1143.             }
  1144.         }
  1145.     }
  1146.  
  1147.     if (pic->scaleengine && data->coords)
  1148.     {
  1149.         DeleteScaleEngine(pic->scaleengine);
  1150.         pic->scaleengine = NULL;
  1151.     }
  1152.  
  1153.     return success;
  1154. }
  1155.  
  1156.  
  1157.  
  1158. /*********************************************************************
  1159. ----------------------------------------------------------------------
  1160.  
  1161.     success = MapPalette(drawhandle, palette, pentab, tags);
  1162.  
  1163.         mappt eine Palette auf ein Drawhandle und
  1164.         erzeugt dafür eine PenTable.
  1165.  
  1166.         GGFX_NumColors        Anzahl Farben in der Palette
  1167.         GGFX_PaletteFormat    Format der Palette
  1168.     
  1169. ----------------------------------------------------------------------
  1170. *********************************************************************/
  1171.  
  1172. BOOL SAVE_DS ASM MapPaletteA(
  1173.     REG(a0) DRAWHANDLE *dh,
  1174.     REG(a1) APTR palette,
  1175.     REG(a2) UBYTE *pentab,
  1176.     REG(a3) TAGLIST tags)
  1177. {
  1178.     BOOL success;
  1179.     
  1180.     int i;
  1181.     ULONG rgb;
  1182.     ULONG *p = (ULONG *) palette;
  1183.  
  1184.     ULONG numcolors;
  1185.     success = FALSE;
  1186.     
  1187.     if (numcolors = GetTagData(GGFX_NumColors, 0, tags))
  1188.     {
  1189.         switch (GetTagData(GGFX_PaletteFormat, PALFMT_RGB8, tags))
  1190.         {
  1191.             case PALFMT_RGB8:
  1192.                 for(i=0; i<numcolors; ++i)
  1193.                 {
  1194.                     *pentab++ = dh->mainpentab[BestPen(dh->realpalette, *p++)];
  1195.                 }
  1196.                 success = TRUE;
  1197.                 break;
  1198.     
  1199.             case PALFMT_RGB32:
  1200.                 for(i=0; i<numcolors; ++i)
  1201.                 {
  1202.                     rgb = p[0] & 0xff000000 >> 8 
  1203.                         + p[1] & 0xff000000 >> 16
  1204.                         + p[2] & 0xff000000 >> 24;
  1205.     
  1206.                     *pentab++ = dh->mainpentab[BestPen(dh->realpalette, rgb)];
  1207.                     p += 3;
  1208.                 }
  1209.                 success = TRUE;
  1210.                 break;
  1211.         }
  1212.     }
  1213.     
  1214.     return success;
  1215. }
  1216.  
  1217.  
  1218. /*********************************************************************
  1219. ----------------------------------------------------------------------
  1220.  
  1221.     pen = MapPen(drawhandle, RGB, tags);
  1222.  
  1223.         mappt einen RGB auf ein Drawhandle und
  1224.         liefert dafür den entsprechenden Pen.
  1225.     
  1226. ----------------------------------------------------------------------
  1227. *********************************************************************/
  1228.  
  1229. LONG SAVE_DS ASM MapPenA(REG(a0) DRAWHANDLE *dh, REG(d0) ULONG rgb, REG(a1) TAGLIST tags)
  1230. {
  1231.     return dh->mainpentab[BestPen(dh->realpalette, rgb)];
  1232. }
  1233.  
  1234.  
  1235.  
  1236. /*********************************************************************
  1237. ----------------------------------------------------------------------
  1238.  
  1239.     success = CreatePictureMask(picture, array, arraywidth, tags);
  1240.  
  1241.         GGFX_SourceWidth            
  1242.         GGFX_SourceHeight            
  1243.         GGFX_SourceX
  1244.         GGFX_SourceY
  1245.  
  1246.         GGFX_DestWidth                skalierte Breite
  1247.         GGFX_DestHeight            skalierte Höhe
  1248.     //    GGFX_DestX
  1249.     //    GGFX_DestY
  1250.         
  1251.         GGFX_Ratio                    
  1252.     
  1253. ----------------------------------------------------------------------
  1254. *********************************************************************/
  1255.  
  1256. BOOL SAVE_DS ASM CreatePictureMaskA(REG(a0) PIC *pic, REG(a1) UBYTE *array, REG(d0) UWORD arraywidth, REG(a2) TAGLIST tags)
  1257. {
  1258.     BOOL success = FALSE;
  1259.  
  1260.     ObtainSemaphore(&pic->semaphore);
  1261.  
  1262.     if (pic)
  1263.     {
  1264.         UBYTE *p;
  1265.         int sourcex, sourcey, sourcewidth, sourceheight, destwidth, destheight;
  1266.     //    int destx, desty;
  1267.         int threshold;
  1268.         int x, y;
  1269.         int bitmask;
  1270.         int realsourcewidth;
  1271.         
  1272.         sourcex = GetTagData(GGFX_SourceX, 0, tags);
  1273.         sourcey = GetTagData(GGFX_SourceY, 0, tags);
  1274.         sourcewidth = GetTagData(GGFX_SourceWidth, pic->width, tags);
  1275.         sourceheight = GetTagData(GGFX_SourceHeight, pic->height, tags);
  1276.  
  1277.     //    destx = GetTagData(GGFX_DestX, 0, tags);
  1278.     //    desty = GetTagData(GGFX_DestY, 0, tags);
  1279.         destwidth = GetTagData(GGFX_DestWidth, pic->width, tags);
  1280.         destheight = GetTagData(GGFX_DestHeight, pic->height, tags);
  1281.  
  1282.         threshold = GetTagData(GGFX_Ratio, 128, tags);
  1283.  
  1284.         if (ExtractAlphaArray(pic))
  1285.         {
  1286.             success = TRUE;
  1287.     
  1288.             if (pic->alphaarray)
  1289.             {
  1290.                 UBYTE *temparray = NULL;
  1291.                 
  1292.                 p = pic->alphaarray + sourcex + sourcey * pic->width;
  1293.                 realsourcewidth = pic->width;
  1294.                 
  1295.                 if (sourcewidth != destwidth || sourceheight != destheight)
  1296.                 {
  1297.                     success = FALSE;
  1298.                     
  1299.                     DB(kprintf("*** scaling mask bitmap\n"));
  1300.     
  1301.                     if (temparray = AllocRenderVec(MemHandler, destwidth*destheight))
  1302.                     {
  1303.                         APTR scaleengine;
  1304.     
  1305.                         if (scaleengine = CreateScaleEngine(sourcewidth, sourceheight,
  1306.                             destwidth, destheight, RND_RMHandler, MemHandler, TAG_DONE))
  1307.                         {
  1308.                             if (Scale(scaleengine, p, temparray,
  1309.                                 RND_SourceWidth, pic->width, TAG_DONE) == CONV_SUCCESS)
  1310.                             {
  1311.                                 success = TRUE;
  1312.                                 p = temparray;
  1313.                                 realsourcewidth = destwidth;
  1314.                             }
  1315.                         
  1316.                             DeleteScaleEngine(scaleengine);
  1317.                         }
  1318.                     }
  1319.                 }
  1320.                 
  1321.                 if (success)
  1322.                 {            
  1323.                     for (y = 0; y < destheight; ++y)
  1324.                     {
  1325.                         bitmask = 0x80;
  1326.                     
  1327.                         for (x = 0; x < destwidth; ++x)
  1328.                         {                    
  1329.                             if (*p++ >= threshold)
  1330.                             {
  1331.                                 array[x>>3] |= bitmask;
  1332.                             }
  1333.                             else
  1334.                             {
  1335.                                 array[x>>3] &= ~bitmask; 
  1336.                             }
  1337.         
  1338.                             if (!(bitmask >>= 1))
  1339.                             {
  1340.                                 bitmask = 0x80;
  1341.                             }
  1342.                         }
  1343.                         p += realsourcewidth - destwidth;
  1344.                         array += arraywidth;
  1345.                     }
  1346.                 }
  1347.                 
  1348.                 if (temparray)
  1349.                 {
  1350.                     FreeRenderVec(temparray);
  1351.                 }
  1352.             }
  1353.             else
  1354.             {
  1355.                 for (y = 0; y < destheight; ++y)
  1356.                 {
  1357.                     bitmask = 0x80;
  1358.     
  1359.                     for (x = 0; x < destwidth; ++x)
  1360.                     {
  1361.                         array[x>>3] |= bitmask;
  1362.                         if (!(bitmask >>= 1))
  1363.                         {
  1364.                             bitmask = 0x80;
  1365.                         }
  1366.                     }
  1367.                     array += arraywidth;
  1368.                 }
  1369.             }
  1370.         }
  1371.     }
  1372.  
  1373.     ReleaseSemaphore(&pic->semaphore);
  1374.  
  1375.     return success;
  1376. }
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383. /*********************************************************************
  1384. ----------------------------------------------------------------------
  1385.  
  1386.     TEST VERSION: pic=NULL zulässig
  1387.  
  1388.     bitmap = CreatePictureBitMap(drawhandle, pic, tags);
  1389.  
  1390.         GGFX_DestWidth                skalierte Breite
  1391.         GGFX_DestHeight                skalierte Höhe
  1392.         GGFX_SourceWidth            
  1393.         GGFX_SourceHeight            
  1394.         GGFX_SourceX
  1395.         GGFX_SourceY
  1396.  
  1397.         GGFX_DitherMode
  1398.         GGFX_DitherAmount
  1399.  
  1400.         erzeugt aus einem Array eine auf das DrawHandle angepaßte Bitmap.
  1401.     
  1402. ----------------------------------------------------------------------
  1403. *********************************************************************/
  1404.  
  1405. struct BitMap SAVE_DS ASM *CreatePictureBitMapA(REG(a0) DRAWHANDLE *dh, REG(a1) PIC *pic, REG(a2) TAGLIST tags)
  1406. {
  1407.     BOOL success = FALSE;
  1408.     struct BitMap *bm = NULL;
  1409.  
  1410.     if (dh)
  1411.     {
  1412. //        ULONG pixelformat;
  1413.         LONG depth;
  1414.         UWORD destwidth, destheight;
  1415.         ULONG additional_flags = 0;
  1416.  
  1417.         if (pic)
  1418.         {
  1419.             ObtainSemaphore(&pic->semaphore);
  1420.  
  1421.             destwidth = GetTagData(GGFX_DestWidth, pic->width, tags);
  1422.             destheight = GetTagData(GGFX_DestHeight, pic->height, tags);
  1423.         
  1424.             if (PrepareDrawing(pic))
  1425.             {
  1426.         
  1427.                 if (dh->rasthandle->colormode != COLORMODE_CLUT)
  1428.                 {
  1429.                     if (!pic->directdraw)
  1430.                     {
  1431.                         /*
  1432.                          *    für HAM: versuchen, auf RGB umzurechnen. Wenn
  1433.                          *    das nicht klappt, ist's auch nicht weiter schlimm.
  1434.                          */
  1435.                 
  1436.                         PIC_Render(pic, PIXFMT_0RGB_32, NULL);
  1437.                     }
  1438.                 }
  1439.         
  1440.                 success = TRUE;
  1441.             }
  1442.         }
  1443.         else
  1444.         {
  1445.             destwidth = GetTagData(GGFX_DestWidth, 0, tags);
  1446.             destheight = GetTagData(GGFX_DestHeight, 0, tags);
  1447.             additional_flags = BMF_CLEAR;
  1448.             success = (destwidth && destheight);
  1449.             
  1450.         }
  1451.  
  1452.         if (success)
  1453.         {
  1454.             GetBitMapInfo(dh->rasthandle->rp->BitMap, dh->modeID,
  1455.                 BMAPATTR_Depth, &depth, TAG_DONE);
  1456.  
  1457.             switch (dh->rasthandle->drawmode)
  1458.             {
  1459.                 case DRAWMODE_CYBERGFX:
  1460.                 {
  1461.                     bm = AllocBitMap(destwidth, destheight, depth, BMF_MINPLANES | additional_flags, dh->rasthandle->rp->BitMap);
  1462.                     break;
  1463.                 }
  1464.                 
  1465.                 case DRAWMODE_WRITECHUNKYPIXELS:
  1466.                 case DRAWMODE_WRITEPIXELARRAY:
  1467.                 {
  1468.                     bm = AllocBitMap(destwidth, destheight, depth, additional_flags, dh->rasthandle->rp->BitMap);
  1469.                     break;
  1470.                 }
  1471.             
  1472.                 case DRAWMODE_BITMAP:
  1473.                 {
  1474.                     bm = AllocBitMap(destwidth, destheight, depth, BMF_STANDARD | additional_flags, dh->rasthandle->rp->BitMap);
  1475.                     break;
  1476.                 }
  1477.             }
  1478.             
  1479.             success = !!bm;
  1480.         }
  1481.  
  1482.             
  1483.         if (success && pic)
  1484.         {
  1485.             RASTHANDLE *rh;
  1486.             struct RastPort rp;
  1487.             
  1488.             success = FALSE;
  1489.         
  1490.             InitRastPort(&rp);
  1491.             rp.BitMap = bm;
  1492.         
  1493.             if (rh = CreateRastHandle(&rp, dh->modeID))
  1494.             {
  1495.                 struct DrawData *data;
  1496.             
  1497.                 if (data = CreateDrawData(dh, pic))
  1498.                 {
  1499.                     data->sourcex = GetTagData(GGFX_SourceX, 0, tags);
  1500.                     data->sourcey = GetTagData(GGFX_SourceY, 0, tags);
  1501.                     data->sourcewidth = GetTagData(GGFX_SourceWidth, pic->width, tags);
  1502.                     data->sourceheight = GetTagData(GGFX_SourceHeight, pic->height, tags);
  1503.                     data->destwidth = destwidth;
  1504.                     data->destheight = destheight;
  1505.                     data->autodither = GetTagData(GGFX_AutoDither, dh->autodither, tags);
  1506.                     data->dithermode = GetTagData(GGFX_DitherMode, dh->dithermode, tags);
  1507.                     data->ditheramount = GetTagData(GGFX_DitherAmount, dh->ditheramount, tags);
  1508.                     data->callbackhook = (struct Hook *) GetTagData(GGFX_CallBackHook, NULL, tags);
  1509.                     data->usescalepixelarray = FALSE;
  1510.                     data->rastlock = NULL;
  1511.  
  1512.                     success = DrawRastHandle(rh, data);
  1513.         
  1514.                     FreeRenderVec(data);
  1515.                 }
  1516.         
  1517.                 DeleteRastHandle(rh);
  1518.             }
  1519.         }
  1520.  
  1521.         if (!success)
  1522.         {
  1523.             if (bm)
  1524.             {
  1525.                 FreeBitMap(bm);
  1526.                 bm = NULL;
  1527.             }
  1528.         }
  1529.  
  1530.         if (pic)
  1531.         {
  1532.             ReleaseSemaphore(&pic->semaphore);
  1533.         }
  1534.  
  1535.     }
  1536.  
  1537.     return bm;
  1538.  
  1539. }
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549. /*********************************************************************
  1550. ----------------------------------------------------------------------
  1551.  
  1552.     success = DrawPictureA(drawhandle,pic,x,y,tags);
  1553.  
  1554.     Zeichnet ein Bild via DrawHandle.
  1555.  
  1556.     GGFX_DestWidth                skalierte Breite
  1557.     GGFX_DestHeight                skalierte Höhe
  1558.     GGFX_SourceWidth            Ausgangsbreite
  1559.     GGFX_SourceHeight            Ausgangshöhe
  1560.     GGFX_SourceX                Start-X
  1561.     GGFX_SourceY                Start-Y
  1562.     GGFX_DitherMode
  1563.     GGFX_DitherAmount
  1564.     GGFX_CallbackHook            für Zeichenoperationen
  1565.     GGFX_RastLock
  1566.  
  1567.  
  1568.     TEST:
  1569.     
  1570.     RND_DestCoordinates
  1571.  
  1572. ----------------------------------------------------------------------
  1573. *********************************************************************/
  1574.  
  1575. BOOL SAVE_DS ASM DrawPictureA(
  1576.     REG(a0) DRAWHANDLE *dh,
  1577.     REG(a1) PIC *pic,
  1578.     REG(d0) UWORD x,
  1579.     REG(d1) UWORD y,
  1580.     REG(a2) TAGLIST tags)
  1581. {
  1582.  
  1583.     BOOL success = TRUE;
  1584.  
  1585.     DB(kprintf("x,y: %ld,%ld\n", x,y));
  1586.  
  1587.     ObtainSemaphore(&pic->semaphore);
  1588.  
  1589.     if (PrepareDrawing(pic))
  1590.     {
  1591.         struct DrawData *data;
  1592.  
  1593.         if (dh->rasthandle->colormode != COLORMODE_CLUT)
  1594.         {
  1595.             if (!pic->directdraw)
  1596.             {
  1597.                 /*
  1598.                  *    für HAM: versuchen, auf RGB umzurechnen. Wenn
  1599.                  *    das nicht klappt, ist's auch nicht weiter schlimm.
  1600.                  */
  1601.         
  1602.                 PIC_Render(pic, PIXFMT_0RGB_32, NULL);
  1603.             }
  1604.         }
  1605.  
  1606.         if (data = CreateDrawData(dh, pic))
  1607.         {
  1608.             data->sourcex = GetTagData(GGFX_SourceX, 0, tags);
  1609.             data->sourcey = GetTagData(GGFX_SourceY, 0, tags);
  1610.             data->sourcewidth = GetTagData(GGFX_SourceWidth, pic->width, tags);
  1611.             data->sourceheight = GetTagData(GGFX_SourceHeight, pic->height, tags);
  1612.             data->destx = x;
  1613.             data->desty = y;
  1614.             data->destwidth = GetTagData(GGFX_DestWidth, pic->width, tags);
  1615.             data->destheight = GetTagData(GGFX_DestHeight, pic->height, tags);
  1616.             data->dithermode = GetTagData(GGFX_DitherMode, dh->dithermode, tags);
  1617.             data->ditheramount = GetTagData(GGFX_DitherAmount, dh->ditheramount, tags);
  1618.             data->callbackhook = (struct Hook *) GetTagData(GGFX_CallBackHook, NULL, tags);
  1619.             data->autodither = GetTagData(GGFX_AutoDither, dh->autodither, tags);
  1620.             data->rastlock = (struct SignalSemaphore *) GetTagData(GGFX_RastLock, NULL, tags);
  1621.  
  1622.             data->coords = (WORD *) GetTagData(RND_DestCoordinates, NULL, tags);
  1623.  
  1624.             data->clearbg = !!data->coords;
  1625.         //    data->bgcolor = GetTagData(GGFX_BGColor, 0x000000, tags);
  1626.             
  1627.             data->usescalepixelarray = env_usescalepixelarray;
  1628.             
  1629.             success = DrawRastHandle(dh->rasthandle, data);
  1630.     
  1631.             FreeRenderVec(data);
  1632.         }
  1633.     }
  1634.  
  1635.     ReleaseSemaphore(&pic->semaphore);        ///    !!!
  1636.  
  1637.     return success;
  1638. }
  1639.  
  1640.  
  1641. //////////////////////////////////////////////////////////////////////
  1642.  
  1643.  
  1644.  
  1645.  
  1646. /*********************************************************************
  1647. ----------------------------------------------------------------------
  1648.  
  1649.     DeleteDirectDrawHandleA(directdrawhandle);
  1650.  
  1651. ----------------------------------------------------------------------
  1652. *********************************************************************/
  1653.  
  1654. void SAVE_DS ASM DeleteDirectDrawHandle(REG(a0) DIRECTDRAWHANDLE *ddh)
  1655. {
  1656.     if (ddh)
  1657.     {
  1658.         FreeRenderVec(ddh->scalebuffer);
  1659.         FreeRenderVec(ddh->mapbuffer);
  1660.         if (ddh->scaleengine)
  1661.         {
  1662.             DeleteScaleEngine(ddh->scaleengine);
  1663.         }
  1664.         FreeRenderVec(ddh);
  1665.     }
  1666. }
  1667.  
  1668.  
  1669. /*********************************************************************
  1670. ----------------------------------------------------------------------
  1671.  
  1672.     directdrawhandle = CreateDirectDrawHandleA(drawhandle,
  1673.         sourcewidth, sourceheight, destwidth, destheight, tags);
  1674.  
  1675.     anfordern eines Direct-Draw-Handles für
  1676.     LowLevel-Rendern/Skalieren
  1677.  
  1678.     GGFX_PixelFormat    Default:    PIXFMT_0RGB_32
  1679.  
  1680. ----------------------------------------------------------------------
  1681. *********************************************************************/
  1682.  
  1683. DIRECTDRAWHANDLE SAVE_DS ASM *CreateDirectDrawHandleA(
  1684.     REG(a0) DRAWHANDLE *dh,
  1685.     REG(d0) UWORD sourcewidth,
  1686.     REG(d1) UWORD sourceheight,
  1687.     REG(d2) UWORD destwidth,
  1688.     REG(d3) UWORD destheight,
  1689.     REG(a1) TAGLIST tags)
  1690. {
  1691.     DIRECTDRAWHANDLE *ddh = NULL;
  1692.     BOOL success = FALSE;
  1693.     int pixelformat = GetTagData(GGFX_PixelFormat, PIXFMT_0RGB_32, tags);
  1694.     
  1695.  
  1696.     if (dh)
  1697.     {
  1698.  
  1699.         switch (pixelformat)
  1700.         {
  1701.  
  1702.             case PIXFMT_0RGB_32:
  1703.  
  1704.                 if (ddh = AllocRenderVecClear(MemHandler, sizeof(DIRECTDRAWHANDLE)))
  1705.                 {
  1706.                     BOOL scaling_is_involved = (sourcewidth != destwidth || sourceheight != destheight);
  1707.                     BOOL source_is_smaller = (sourcewidth*sourceheight < destwidth*destheight);
  1708.                     BOOL dest_is_truecolor = dh->rasthandle->truecolor;
  1709.                     BOOL mapping_is_involved = FALSE;
  1710.                     int scalepixelformat = PIXFMT_CHUNKY_CLUT;
  1711.                     int scalebuffersize = 0;
  1712.                     int mapbuffersize = 0;
  1713.                 
  1714.                     ddh->pixelformat = pixelformat;
  1715.                     ddh->sourcewidth = sourcewidth;
  1716.                     ddh->sourceheight = sourceheight;
  1717.                     ddh->destwidth = destwidth;
  1718.                     ddh->destheight = destheight;
  1719.                     ddh->dh = dh;
  1720.         
  1721.         
  1722.                     if (dest_is_truecolor)
  1723.                     {
  1724.                         if (scaling_is_involved)
  1725.                         {
  1726.                             ddh->drawmode = DDMODE_SCALEDRAW;
  1727.                             scalepixelformat = PIXFMT_0RGB_32;
  1728.                             if (!(cgfx41 /*&& env_usescalepixelarray*/))
  1729.                             {
  1730.                                 scalebuffersize = destwidth * destheight * 4;
  1731.                             }
  1732.                         }
  1733.                         else
  1734.                         {
  1735.                             ddh->drawmode = DDMODE_DRAW;
  1736.                         }
  1737.                     }
  1738.                     else
  1739.                     {
  1740.                         mapping_is_involved = TRUE;
  1741.                         if (source_is_smaller)
  1742.                         {
  1743.                             ddh->drawmode = DDMODE_MAPSCALEDRAW;
  1744.                             scalepixelformat = PIXFMT_CHUNKY_CLUT;
  1745.                             scalebuffersize = destwidth * destheight;
  1746.                             mapbuffersize = sourcewidth * sourceheight;
  1747.                         }
  1748.                         else
  1749.                         {
  1750.                             if (scaling_is_involved)
  1751.                             {
  1752.                                 ddh->drawmode = DDMODE_SCALEMAPDRAW;
  1753.                                 scalepixelformat = PIXFMT_0RGB_32;
  1754.                                 scalebuffersize = destwidth * destheight * 4;
  1755.                                 // no mapbuffer required. mapping can be performed over itself.
  1756.                             }
  1757.                             else
  1758.                             {
  1759.                                 ddh->drawmode = DDMODE_MAPDRAW;
  1760.                                 mapbuffersize = destwidth * destheight;
  1761.                             }
  1762.                         }
  1763.                     }
  1764.         
  1765.                     success = TRUE;
  1766.                     
  1767.                     if (scaling_is_involved)
  1768.                     {
  1769.                         success = !!(ddh->scaleengine = CreateScaleEngine(sourcewidth, sourceheight,
  1770.                                 destwidth, destheight, RND_PixelFormat, scalepixelformat,
  1771.                                 RND_RMHandler, MemHandler, TAG_DONE));
  1772.                     }
  1773.         
  1774.                     if (success && mapping_is_involved)
  1775.                     {
  1776.                         ObtainSemaphore(&dh->mapsemaphore);
  1777.                         if (!dh->mapengine)
  1778.                         {
  1779.                             success = !!(dh->mapengine = CreateMapEngine(dh->realpalette,
  1780.                                     RND_RMHandler, MemHandler, TAG_DONE));
  1781.                         }
  1782.                         ReleaseSemaphore(&dh->mapsemaphore);
  1783.                     }
  1784.         
  1785.                     if (success && scalebuffersize)
  1786.                     {
  1787.                         success = !!(ddh->scalebuffer = AllocRenderVec(MemHandler, scalebuffersize));
  1788.                     }
  1789.         
  1790.                     if (success && mapbuffersize)
  1791.                     {
  1792.                         success = !!(ddh->mapbuffer = AllocRenderVec(MemHandler, mapbuffersize));
  1793.                     }
  1794.                 }
  1795.                 break;
  1796.  
  1797. /***************************************
  1798.  
  1799.             case PIXFMT_CHUNKY_CLUT:
  1800.  
  1801.                 if (ddh = AllocRenderVecClear(MemHandler, sizeof(DIRECTDRAWHANDLE)))
  1802.                 {
  1803.                     BOOL scaling_is_involved = (sourcewidth != destwidth || sourceheight != destheight);
  1804.                     BOOL source_is_smaller = (sourcewidth*sourceheight < destwidth*destheight);
  1805.                     BOOL dest_is_truecolor = dh->rasthandle->truecolor;
  1806.                     BOOL mapping_is_involved = FALSE;
  1807.                     int scalepixelformat = PIXFMT_CHUNKY_CLUT;
  1808.                     int scalebuffersize = 0;
  1809.                     int mapbuffersize = 0;
  1810.                 
  1811.                     ddh->pixelformat = pixelformat;
  1812.                     ddh->sourcewidth = sourcewidth;
  1813.                     ddh->sourceheight = sourceheight;
  1814.                     ddh->destwidth = destwidth;
  1815.                     ddh->destheight = destheight;
  1816.                     ddh->dh = dh;
  1817.         
  1818.         
  1819.                     if (dest_is_truecolor)
  1820.                     {
  1821.                         if (scaling_is_involved)
  1822.                         {
  1823.                             if (cgfx41)
  1824.                             {
  1825.                                 // chunky->rgb, mit ScalePixelArray() zeichnen
  1826.  
  1827.                             }
  1828.                             else
  1829.                             {
  1830.                                 if (source_is_smaller)
  1831.                                 {
  1832.                                     // chunky->rgb, rgb skalieren, zeichnen
  1833.  
  1834.                                 }
  1835.                                 else
  1836.                                 {
  1837.                                     // chunky skalieren, chunky->rgb, zeichnen
  1838.                                 }
  1839.                             }
  1840.                         }
  1841.                         else
  1842.                         {
  1843.                             // chunky->rgb, zeichnen
  1844.  
  1845.                         }
  1846.                     }
  1847.                     else
  1848.                     {
  1849.                         if (scaling_is_involved)
  1850.                         {
  1851.                             if (source_is_smaller)
  1852.                             {
  1853.                                 // chunky mappen, skalieren, zeichnen
  1854.                             }
  1855.                             else
  1856.                             {
  1857.                                 // chunky skalieren, mappen, zeichnen
  1858.                             }
  1859.                         }
  1860.                         else
  1861.                         {
  1862.                             // chunky mappen, zeichnen
  1863.                         }
  1864.                     }
  1865.         
  1866.                     success = TRUE;
  1867.                     
  1868.                     if (scaling_is_involved)
  1869.                     {
  1870.                         success = !!(ddh->scaleengine = CreateScaleEngine(sourcewidth, sourceheight,
  1871.                                 destwidth, destheight, RND_PixelFormat, scalepixelformat,
  1872.                                 RND_RMHandler, MemHandler, TAG_DONE));
  1873.                     }
  1874.         
  1875.                     if (success && mapping_is_involved)
  1876.                     {
  1877.                         ObtainSemaphore(&dh->mapsemaphore);
  1878.                         if (!dh->mapengine)
  1879.                         {
  1880.                             success = !!(dh->mapengine = CreateMapEngine(dh->realpalette,
  1881.                                     RND_RMHandler, MemHandler, TAG_DONE));
  1882.                         }
  1883.                         ReleaseSemaphore(&dh->mapsemaphore);
  1884.                     }
  1885.         
  1886.                     if (success && scalebuffersize)
  1887.                     {
  1888.                         success = !!(ddh->scalebuffer = AllocRenderVec(MemHandler, scalebuffersize));
  1889.                     }
  1890.         
  1891.                     if (success && mapbuffersize)
  1892.                     {
  1893.                         success = !!(ddh->mapbuffer = AllocRenderVec(MemHandler, mapbuffersize));
  1894.                     }
  1895.                 }
  1896.                 break;
  1897.  
  1898. **************************************************/
  1899.  
  1900.  
  1901.             default:
  1902.                 break;
  1903.  
  1904.         }
  1905.  
  1906.         if (!success)
  1907.         {
  1908.             DeleteDirectDrawHandle(ddh);
  1909.             ddh = NULL;
  1910.         }
  1911.  
  1912.     }
  1913.     
  1914.     return ddh;
  1915. }
  1916.  
  1917.  
  1918. /*********************************************************************
  1919. ----------------------------------------------------------------------
  1920.  
  1921.     success = DirectDrawTruecolorA(directdrawhandle, array, x,y, tags);
  1922.  
  1923.     Zeichnet ein TrueColor-Array auf ein DrawHandle
  1924.     mit minimalem Overhead, ohne Dithering.
  1925.     
  1926.     GGFX_SourceWidth
  1927.  
  1928. ----------------------------------------------------------------------
  1929. *********************************************************************/
  1930.  
  1931. BOOL SAVE_DS ASM DirectDrawTrueColorA(
  1932.     REG(a0) DIRECTDRAWHANDLE *ddh,
  1933.     REG(a1) ULONG *array,
  1934.     REG(d0) UWORD x,
  1935.     REG(d1) UWORD y,
  1936.     REG(a2) TAGLIST tags)
  1937. {
  1938.     BOOL success = FALSE;
  1939.  
  1940.     if (ddh)
  1941.     {
  1942.         int totalsourcewidth;
  1943.         RASTHANDLE *rh = ddh->dh->rasthandle;
  1944.         UBYTE *drawbuffer = NULL;
  1945.     //    int drawwidth, drawheight, drawtotalwidth;
  1946.     
  1947.         totalsourcewidth = GetTagData(GGFX_SourceWidth, ddh->sourcewidth, tags);
  1948.  
  1949.         switch (ddh->drawmode)
  1950.         {
  1951.             case DDMODE_DRAW:
  1952.  
  1953.                 //drawbuffer = (UBYTE *) array;
  1954.                 
  1955.                 WritePixelArray(array, 0, 0, totalsourcewidth * 4,
  1956.                     rh->rp, x, y, ddh->destwidth, ddh->destheight, RECTFMT_ARGB);
  1957.  
  1958.                 success = TRUE;
  1959.                 break;
  1960.  
  1961.             case DDMODE_SCALEDRAW:
  1962.  
  1963.                 if (cgfx41 /* && env_usescalepixelarray*/)
  1964.                 {
  1965.                     ScalePixelArray(array, ddh->sourcewidth, ddh->sourceheight, 
  1966.                             totalsourcewidth*4, rh->rp, x, y, ddh->destwidth,
  1967.                             ddh->destheight, RECTFMT_ARGB);
  1968.                 }
  1969.                 else
  1970.                 {
  1971.                     Scale(ddh->scaleengine, array, ddh->scalebuffer,
  1972.                         RND_SourceWidth, totalsourcewidth, TAG_DONE);
  1973.             
  1974.                     WritePixelArray(ddh->scalebuffer, 0, 0, ddh->destwidth * 4,
  1975.                         rh->rp, x, y, ddh->destwidth, ddh->destheight, RECTFMT_ARGB);
  1976.                 }
  1977.                 success = TRUE;
  1978.                 break;
  1979.             
  1980.             case DDMODE_MAPDRAW:
  1981.             
  1982.                 if (MapRGBArray(ddh->dh->mapengine, array,
  1983.                     ddh->sourcewidth, ddh->sourceheight, ddh->mapbuffer,
  1984.                     RND_SourceWidth, totalsourcewidth,
  1985.                     RND_PenTable, ddh->dh->mainpentab, 
  1986.                     TAG_DONE) == CONV_SUCCESS)
  1987.                 {
  1988.                     drawbuffer = ddh->mapbuffer;
  1989.                 }
  1990.                 break;
  1991.         
  1992.             case DDMODE_SCALEMAPDRAW:
  1993.             
  1994.                 Scale(ddh->scaleengine, array, ddh->scalebuffer,
  1995.                     RND_SourceWidth, totalsourcewidth, TAG_DONE);
  1996.  
  1997.                 if (MapRGBArray(ddh->dh->mapengine, ddh->scalebuffer,
  1998.                     ddh->destwidth, ddh->destheight, ddh->scalebuffer,
  1999.                     RND_PenTable, ddh->dh->mainpentab,
  2000.                     TAG_DONE) == CONV_SUCCESS)
  2001.                 {
  2002.                     drawbuffer = ddh->scalebuffer;
  2003.                 }
  2004.                 break;
  2005.  
  2006.             case DDMODE_MAPSCALEDRAW:
  2007.             
  2008.                 if (MapRGBArray(ddh->dh->mapengine, array,
  2009.                     ddh->sourcewidth, ddh->sourceheight, ddh->mapbuffer,
  2010.                     RND_SourceWidth, totalsourcewidth,
  2011.                     RND_PenTable, ddh->dh->mainpentab, 
  2012.                     TAG_DONE) == CONV_SUCCESS)
  2013.                 {
  2014.                     Scale(ddh->scaleengine, ddh->mapbuffer, ddh->scalebuffer, NULL);
  2015.                     drawbuffer = ddh->scalebuffer;
  2016.                 }
  2017.                 break;
  2018.             
  2019.             default:
  2020.                 break;
  2021.         }
  2022.  
  2023.  
  2024.         if (drawbuffer)
  2025.         {
  2026.             switch (rh->drawmode)
  2027.             {
  2028.                 case DRAWMODE_CYBERGFX:
  2029.                 {
  2030.                     WritePixelArray(drawbuffer, 0, 0, ddh->destwidth,
  2031.                         rh->rp, x, y, ddh->destwidth, ddh->destheight, RECTFMT_LUT8);
  2032.                     break;
  2033.                 }
  2034.  
  2035.                 case DRAWMODE_WRITEPIXELARRAY:
  2036.                 {
  2037.                     if (gfx40)
  2038.                     {
  2039.                         WriteChunkyPixels(rh->rp, x, y, x+ddh->destwidth-1, y+ddh->destheight-1,
  2040.                             (APTR) drawbuffer, ddh->destwidth);
  2041.                     }
  2042.                     else
  2043.                     {
  2044.                         if (ddh->destwidth & 15)
  2045.                         {
  2046.                             int i;
  2047.                             char *p = drawbuffer;
  2048.                             for (i = y; i < y + ddh->destheight; ++i)
  2049.                             {
  2050.                                 WritePixelLine8(rh->rp, x, i, ddh->destwidth, (APTR) p, rh->temprp);
  2051.                                 p += ddh->destwidth;
  2052.                             }
  2053.                         }
  2054.                         else
  2055.                         {
  2056.                             WritePixelArray8(rh->rp, x, y, x+ddh->destwidth-1, y+ddh->destheight-1,
  2057.                                 drawbuffer, rh->temprp);
  2058.                         }
  2059.                     }                
  2060.                     break;
  2061.                 }
  2062.                 
  2063.                 case DRAWMODE_BITMAP:
  2064.                 {
  2065.                     struct BitMap *bm;
  2066.                     if (bm = AllocBitMap(ddh->destwidth, ddh->destheight,
  2067.                         rh->rp->BitMap->Depth, BMF_STANDARD+BMF_INTERLEAVED, NULL))
  2068.                     {
  2069.                         Chunky2BitMap(drawbuffer, 0,0, ddh->destwidth, ddh->destheight,
  2070.                             bm, 0,0, NULL);
  2071.         
  2072.                         BltBitMapRastPort(bm, 0, 0, rh->rp, x, y,
  2073.                             ddh->destwidth, ddh->destheight, 0xc0);
  2074.         
  2075.                         FreeBitMap(bm);
  2076.                     }
  2077.                     break;
  2078.                 }
  2079.             }
  2080.             success = TRUE;
  2081.         }
  2082.  
  2083.     }
  2084.  
  2085.     return success;
  2086. }
  2087.  
  2088.